package uk.ac.cam.echo.app;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class ExtendedActivity extends Activity
{
	protected ExtendedActivity self = this;

	protected void showView(final View animation)
	{
		animation.post(new Runnable()
		{

			@Override
			public void run()
			{
				animation.setVisibility(View.VISIBLE);
			}
		});
	}

	protected void hideView(final View animation)
	{
		animation.post(new Runnable()
		{

			@Override
			public void run()
			{
				animation.setVisibility(View.GONE);
			}
		});
	}

	protected void enableButton(final Button b)
	{
		b.post(new Runnable()
		{
			@Override
			public void run()
			{
				b.setEnabled(true);
			}
		});
	}

	protected void disableButton(final Button b)
	{
		b.post(new Runnable()
		{
			@Override
			public void run()
			{
				b.setEnabled(false);
			}
		});
	}

	protected void showOKMessage(final String message)
	{
		self.runOnUiThread(new Runnable()
		{

			@Override
			public void run()
			{
				AlertDialog.Builder builder = new AlertDialog.Builder(self);
				builder.setMessage(message).setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener()
				{
					@Override
					public void onClick(DialogInterface dialog, int which)
					{}
				}).show();
			}
		});
	}

	protected void showMessage(final String message, final boolean quick)
	{
		self.runOnUiThread(new Runnable()
		{

			@Override
			public void run()
			{
				Toast.makeText(self, message, quick ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG).show();
			}
		});
	}
}
